package com.fau.wmbj.server.controller;

import cn.dev33.satoken.stp.SaTokenInfo;
import com.fau.wmbj.server.config.CurrentUser;
import com.fau.wmbj.server.entity.User;
import com.fau.wmbj.server.service.UserService;
import com.fau.wmbj.server.utils.Message;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 登录
 *
 * @author jiawei
 * @version 1.0
 * @datetime 2024-02-20 13:32
 */

@RestController
@RequestMapping("/auth")
public class AuthController {

    @Resource
    private UserService userService;


    /**
     * 登录
     */
    @RequestMapping("/login")
    public Message doLogin(@RequestBody User user) {
        // if ("zhang".equals(user.getUsername()) && "123456".equals(user.getPassword())) {
        //     StpUtil.login(10001);
        //     SaTokenInfo tokenInfo = StpUtil.getTokenInfo();
        //     return Message.success("登录成功", tokenInfo);
        // }
        try {
            SaTokenInfo login = userService.login(user);
            return Message.success(login);
        } catch (Exception e) {
            return Message.error(e.getMessage());
        }
    }

    @RequestMapping("/getUserInfo")
    public Message getUserInfo(@CurrentUser User user) {
        return Message.success(user);
    }


}
